package com.bee.commons.web.handle;

import com.bee.commons.vo.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

/**
 * controller 统一异常处理
 * @author Damin.yang
 * @date 2019/08/26 18:25
 */
@ControllerAdvice
@Slf4j
public class ExceptionHandle {

    @ExceptionHandler(Exception.class)
    @ResponseBody
    public Result<?> handleException(HttpServletRequest request, Exception exception) {
        log.error(">>> exception: {}", exception);
        return Result.fail(exception.getMessage());
    }

}
